package development;

import particle.core.tools.Color;
import state.GameAlert;
import state.GameConstants;
import state.GameForm;
import state.GameImage;
import state.Graphics;
import state.Key;
import state.RecordStore;
import state.component.BottomBar;
import state.component.Event;
import state.component.EventListener;
import state.component.GameMenu;
import state.component.MenuStyle;
import state.font.FontManager;
import state.font.ImageText;
import state.socket.DataPackage;
import state.util.GameColor;
import state.util.Hashtable;
import state.util.ImageUtil;
import state.util.array.ByteArray;
import stateframework_particle.view.StateFramework_ParticleResources;

public class FrmTestBottomBar extends GameForm implements EventListener {
  private BottomBar bottomBar = null;

  private static GameForm singleton = null;

  public static GameForm instance() {
    if (singleton == null) {
      singleton = new FrmTestBottomBar();
    }
    return singleton;
  }
  
  private GameImage menuItemBackground = null;
  private String testString = null;
  private ImageText font13 = null;

  public void init(Hashtable parameters) {
    menuItemBackground = new GameImage(StateFramework_ParticleResources.image_bg_menu, null, null).setStatic(true);
    menuItemBackground = ImageUtil.joinAndCreateImages(menuItemBackground, 120, menuItemBackground.getHeight());
    
    MenuStyle MENU_STYLE = new MenuStyle();
    MENU_STYLE.setBorderColor(GameColor.WHITE_CODE);
    MENU_STYLE.setItemBackgroundImage(menuItemBackground);
    MENU_STYLE.setForceGroundColor(GameColor.WHITE_CODE);
    MENU_STYLE.setFocusFgColor(GameColor.RED2_CODE);
    MENU_STYLE.setItemHeight(20);
    MENU_STYLE.setItemWidth(120);
    MENU_STYLE.setFont(FontManager.getFont(FontManager.FONT_SIZE_8));
    MENU_STYLE.setTextDx(5);
    MENU_STYLE.setTextDy(2);

    GameMenu menu = new GameMenu(null, new String[]{"Đăng ký TK", "Quên mật khẩu", "Giới thiệu", "Hotline hỗ trợ", "Thoát"}, 5, this, MENU_STYLE, 0, GameConstants.SCREEN_HEIGHT - 45);
    bottomBar = new BottomBar(_manager, 25);
    GameImage bottomBarImage = new GameImage(StateFramework_ParticleResources.image_bg_footer, null, null).setStatic(true);
    bottomBarImage = ImageUtil.joinAndCreateImages(bottomBarImage, Constants.SCREEN_WIDTH, bottomBarImage.getHeight());
    bottomBar.setImage(bottomBarImage);
    bottomBar.setLabels("Menu", "Center menu", "Back");
    bottomBar.setLeftMenu("Menu", menu);

    _manager.setBackGroundColor(GameColor.BLACK_CODE);
    _manager.enableTouchPad();
    
    
    testString = "Tiếng Việt có dấu";
    
    DataPackage dataPackage = DataPackage.createDataPackage1(0);
    dataPackage.putString(testString);
    ByteArray data = dataPackage.getAllData();
    RecordStore recordStore = RecordStore.openRecordStore("data");
    recordStore.addRecord(data, 0, data.len());
    
    //////////////////////////////////////////////////////
    RecordStore recordStore1 = RecordStore.openRecordStore("data");
    data = recordStore1.getRecord(1);
    DataPackage dataPackage2 = DataPackage.createDataPackage(data);
    testString = dataPackage2.nextString();
    font13 = FontManager.getFont(FontManager.FONT_SIZE_13);
  }
  
  public void draw(Graphics g) {
    font13.drawString2(g, testString, Color.Green, 100, 100, Constants.TOP_LEFT_ANCHOR);
  }

  public void keyRepeated(int keyCode) {
  }

  public void keyReleased(int keyCode) {
    if (bottomBar.isMenuShowing()) {
      return;
    }

    switch (keyCode) {
    case Key.SOFT_RIGHT:
      Global.nextState(FrmMenu.instance(), null);
      break;
    case Key.FIRE:
      Global.alert.showAlert(this, GameAlert.OK_TYPE, "User pressed FIRE");
      break;
    }
  }

  public void onActionPerform(Event event1) {
    Global.alert.showAlert(this, GameAlert.OK_TYPE, "You pressed label: " + event1.getAction());
  }

  public void destroy() {
    bottomBar.detroy();
    bottomBar = null;
  }
}
